﻿using System.Text.RegularExpressions;

namespace Rosetta.Default.AddIns.RegularExpressions
{
    public sealed class RegexInputter : Inputter
    {
        #region Fields

        private string pattern;

        #endregion

        #region Constructors

        public RegexInputter()
            : base("Regex Inputter")
        {
            Category = "RegularExpressions";
            ContextType = typeof(string);

            Add<Regex>("Create", Create);
            Add<Regex>("CreateCompiled", CreateCompiled);
        }

        #endregion

        #region Public Methods

        public override void UseContext(object context)
        {
            pattern = context as string;
        }

        #endregion

        #region Private Methods

        private Regex Create()
        {
            return new Regex(pattern);
        }

        private Regex CreateCompiled()
        {
            return new Regex(pattern, RegexOptions.Compiled);
        }

        #endregion
    }
}